package com.hsurosy.domain.activity.service.quota.rule.factory;

import com.hsurosy.domain.activity.service.quota.rule.IActionChain;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @Author Hsu琛君珩
 * @Date 2024-11-08 19:47
 * @Description 责任链工厂
 * @Version: v1.0.0
 */
@Service
public class DefaultActivityChainFactory {

    private final IActionChain actionChain;

    /**
     * 构造方法，初始化责任链
     *
     * @param actionChainGroup 责任链组，包含各个动作校验链的实现
     */
    public DefaultActivityChainFactory(Map<String, IActionChain> actionChainGroup) {
        // 初始化责任链，先执行活动基础校验，再执行 SKU 库存校验
        actionChain = actionChainGroup.get(ActionModel.activity_base_action.code);
        actionChain.appendNext(actionChainGroup.get(ActionModel.activity_sku_stock_action.getCode()));
    }

    /**
     * 打开责任链
     *
     * @return 初始化后的责任链起始节点
     */
    public IActionChain openActionChain() {
        return this.actionChain;
    }

    /**
     * 责任链动作模型枚举类
     */
    @Getter
    @AllArgsConstructor
    public enum ActionModel {
        activity_base_action("activity_base_action", "活动的时间、状态校验"),
        activity_sku_stock_action("activity_sku_stock_action", "活动sku库存"),
        ;

        private final String code;
        private final String info;
    }

}
